﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using log4net;

using JsonServer.Interfaces;
using JsonServer.Server;

namespace SGData
{
    public class SGDataServer : JsonServerBase
    {
        #region Logging
        protected static readonly ILog _log = LogManager.GetLogger(typeof(JsonServerBase));
        #endregion

        #region State
        protected Config _Cfg = new Config();

        protected SGListener _Listener;
        #endregion

        #region Config
        [XmlRoot(ROOT)]
        public class Config
        {
            public const string ROOT = "Config";

            public string UserId;
            public string Password;

            public int IntervalSecs = 4;
        }
        #endregion

        #region CtorDtor
        static SGDataServer()
        {
        }

        public SGDataServer()
        {
        }

        protected override void Configure(XmlNode cfg)
        {
            base.Configure(cfg);  //TODO

            _Listener = new SGListener(_Cfg.IntervalSecs, _Cfg.UserId, _Cfg.Password);
            _Listener.Connect();
        }
        #endregion

        #region RegisterApi
        protected override void RegisterApi(JsonServerApi api)
        {
            api.Add("GetProducts", GetProducts);
            api.Add("GetPrices", GetPrices);
        }
        #endregion

        protected void GetProducts(Dictionary<string, string> args, Stream inputData, Stream outputStream)
        {
            var dt = _Listener.Snapshot;

        }
        protected void GetPrices(Dictionary<string, string> args, Stream inputData, Stream outputStream)
        {

        }
    }
}
